package internal

import (
	"slices"
)

func Fact(n int) int {
	if n == 1 {
		return 1
	}
	return n * Fact(n-1)
}

func Sum(list []int) int {
	length := len(list)
	if length == 0 {
		return 0
	}
	tail := list[length-1]
	list = slices.Delete(list, length-1, length)
	return tail + Sum(list)
}

func CustomLen(list []int) int {
	length := len(list)
	if length == 0 {
		return 0
	}
	return 1 + CustomLen(list[:length-1])
}

func Max(list []int) int {
	length := len(list)
	if length == 0 {
		return 0
	}
	if length == 1 {
		return list[0]
	}
	first := list[length-1]
	second := list[length-2]
	if first > second {
		list = slices.Delete(list, length-2, length-1)
	} else {
		list = list[:length-1]
	}
	return Max(list)
}
